package com.ruoyi.security.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.security.mapper.FirefighterSecurityMapper;
import com.ruoyi.security.domain.FirefighterSecurity;
import com.ruoyi.security.service.IFirefighterSecurityService;

/**
 * 执行重大安保任务Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-12
 */
@Service
public class FirefighterSecurityServiceImpl implements IFirefighterSecurityService
{
    @Autowired
    private FirefighterSecurityMapper firefighterSecurityMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;
    /**
     * 查询执行重大安保任务
     *
     * @param id 执行重大安保任务主键
     * @return 执行重大安保任务
     */
    @Override
    public FirefighterSecurity selectFirefighterSecurityById(Long id)
    {
        return firefighterSecurityMapper.selectFirefighterSecurityById(id);
    }

    /**
     * 查询执行重大安保任务列表
     *
     * @param firefighterSecurity 执行重大安保任务
     * @return 执行重大安保任务
     */
    @Override
    public List<FirefighterSecurity> selectFirefighterSecurityList(FirefighterSecurity firefighterSecurity)
    {
        return firefighterSecurityMapper.selectFirefighterSecurityList(firefighterSecurity);
    }

    /**
     * 新增执行重大安保任务
     *
     * @param firefighterSecurity 执行重大安保任务
     * @return 结果
     */
    @Override
    public int insertFirefighterSecurity(FirefighterSecurity firefighterSecurity)
    {
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterSecurity.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterSecurity.setFirefighterId(firefighterInfo.getUserId());
        firefighterSecurity.setCreateTime(DateUtils.getNowDate());
        return firefighterSecurityMapper.insertFirefighterSecurity(firefighterSecurity);
    }

    /**
     * 修改执行重大安保任务
     *
     * @param firefighterSecurity 执行重大安保任务
     * @return 结果
     */
    @Override
    public int updateFirefighterSecurity(FirefighterSecurity firefighterSecurity)
    {
        firefighterSecurity.setUpdateTime(DateUtils.getNowDate());
        return firefighterSecurityMapper.updateFirefighterSecurity(firefighterSecurity);
    }

    /**
     * 批量删除执行重大安保任务
     *
     * @param ids 需要删除的执行重大安保任务主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterSecurityByIds(Long[] ids)
    {
        return firefighterSecurityMapper.deleteFirefighterSecurityByIds(ids);
    }

    /**
     * 删除执行重大安保任务信息
     *
     * @param id 执行重大安保任务主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterSecurityById(Long id)
    {
        return firefighterSecurityMapper.deleteFirefighterSecurityById(id);
    }

    @Override
    public    List<FirefighterSecurity>    selectFirefighterSecurityByName(String emergency) {
        return firefighterSecurityMapper.selectFirefighterSecurityByName(emergency);
    }

    @Override
    public void deleteFirefighterSecurityById1(Long userId) {
        firefighterSecurityMapper.deleteFirefighterSecurityById1(userId);
    }
}
